package com.lorenzogao.pley.ui.base

import android.content.Intent
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.lorenzogao.pley.AppApplication
import com.lorenzogao.pley.ui.BaseView
import com.lorenzogao.pley.ui.di.component.AppComponent
import com.lorenzogao.pley.ui.presenter.BasePresenter
import javax.inject.Inject

/**
 * 作者：Lorenzo Gao
 * Date: 2017/12/27
 * Time: 17:34
 * 邮箱：2508719070@qq.com
 * Description:
 */
open abstract class BaseFragment<T : BasePresenter<*, *>> : Fragment(), BaseView {


  protected  lateinit var mApplication: AppApplication


    @Inject
    lateinit var mPresenter: T


    private var rootView: View? = null

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {

        rootView = inflater!!.inflate(setLayout(), container, false)

        this.mApplication = activity.application as AppApplication

        setupActivityComponent(mApplication.getAppComponent())



        initView()

        return rootView
    }


    abstract fun setLayout(): Int


    abstract fun initView()

    fun getViews(): View {
        return rootView!!
    }


    abstract fun setupActivityComponent(appComponent: AppComponent)

    protected fun startActivity(mClass: Class<*>) {
        activity.startActivity(Intent(activity, mClass))
    }

    override fun showLodading() {

    }

    override fun showError(msg: String) {

    }

    override fun dimissLoading() {

    }

    fun getContentView(): View? {

        return rootView
    }

}